package com.cheyun.netsalev3.viewmodel

import android.content.Intent
import android.util.Log
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.cheyun.netsalev3.adapter.SecondaryListAdapter
import com.cheyun.netsalev3.bean.ClueDetails
import com.cheyun.netsalev3.bean.KeyValueParam
import com.cheyun.netsalev3.bean.records.Follow
import com.cheyun.netsalev3.view.CallRecordActivity
import com.cheyun.netsalev3.view.FollowUpListActivity
import org.json.JSONObject
import java.io.Serializable

class ClueDetailMingXiActivityViewModel(var data: ClueDetails, var follow: ArrayList<Follow>) : BaseViewModel() {
    var listdata = MutableLiveData<ArrayList<SecondaryListAdapter.DataTree<String, KeyValueParam>>>()

    init {
        listdata.postValue(data.dataslist)
    }

    fun onClickMor(view: View, groupItemIndex: Int) {
        //更多通话记录
        if (groupItemIndex == data.dataslist.size - 1) {
            var intent = Intent(view.context, CallRecordActivity::class.java)
            intent.putExtra("phone",data.phone)
            view.context.startActivity(intent)
        } else {
            //跟进
            onClickMorFollowup(view)
        }
    }

    /**
     * 点击更多跟进
     */
    fun onClickMorFollowup(view: View) {
        //transfer表示流转记录；键follow表示跟进记录，键call表示通话记录
        var intent = Intent(view.context, FollowUpListActivity::class.java)
        intent.putExtra("data", follow as Serializable)
        view.context.startActivity(intent)
    }

    fun refreshClueDetails(d: ClueDetails){
        data = d
        data.getData()
        listdata.postValue(data.dataslist)
    }
}